import { ItemData } from "../../../resource/info/ItemData";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ItemMenuConst } from "./ItemMenuConst";
import { Global } from "../../../../../com/gengine/global/Global";
import { ListMenu } from "./ListMenu";
import { ListEvent } from "../../../../../fl/events/ListEvent";
import { LayerManager } from "../../../manager/LayerManager";
//class ItemMenuRegister
    
    export  class ItemMenuRegister
    {
        

        public static register(arg1: Object /* flash.display.InteractiveObject */, arg2: ItemData, arg3: DataProvider=null): void
        {
            var loc1=null;
            if (!ItemMenuRegister.hasRegister(arg1)) 
            {
                if (arg3 == null) 
                {
                    loc1 = ItemMenuConst.getDataProvider(arg2);
                }
                else 
                {
                    loc1 = arg3;
                }
                ItemMenuRegister._dicObjInfo[arg1] = arg2;
                ItemMenuRegister._dicObjdata[arg1] = loc1;
                arg1.addEventListener(flash.events.MouseEvent.CLICK, ItemMenuRegister.showInfo);
                Global.stage.addEventListener(flash.events.MouseEvent.CLICK, ItemMenuRegister.hideHandler);
            }
            return;
        }

        public static unRegister(arg1: Object /* flash.display.InteractiveObject */): void
        {
            arg1.removeEventListener(flash.events.MouseEvent.CLICK, ItemMenuRegister.showInfo);
            delete ItemMenuRegister._dicObjInfo[arg1];
            delete ItemMenuRegister._dicObjdata[arg1];
            return;
        }

        public static hasRegister(arg1: Object /* flash.display.InteractiveObject */): Boolean
        {
            return ItemMenuRegister._dicObjInfo.hasOwnProperty(arg1) ? true : false;
        }

        public static hideOpList(): void
        {
            if (ItemMenuRegister._itemList) 
            {
                ItemMenuRegister._itemList.hide();
            }
            return;
        }

        /* internal  */static createItemList(): void
        {
            if (!ItemMenuRegister._itemList) 
            {
                ItemMenuRegister._itemList = new ListMenu();
                ItemMenuRegister._itemList.width = 84;
                ItemMenuRegister._itemList.visible = false;
                ItemMenuRegister._itemList.list.drawNow();
                ItemMenuRegister._itemList.list.addEventListener(ListEvent.ITEM_CLICK, ItemMenuRegister.opItemSelect);
            }
            return;
        }

        /* internal  */static showInfo(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=NaN;
            var loc2=NaN;
            var loc3=NaN;
            if (!ItemMenuRegister._layer) 
            {
                ItemMenuRegister._layer = LayerManager.topLayer;
            }
            ItemMenuRegister.createItemList();
            ItemMenuRegister._currentActiveObject = arg1.target as Object /* flash.display.InteractiveObject */;
            ItemMenuRegister._currentItemData = ItemMenuRegister._dicObjInfo[ItemMenuRegister._currentActiveObject];
            if (ItemMenuRegister._currentActiveObject.parent) 
            {
                ItemMenuRegister._layer.addChild(ItemMenuRegister._itemList);
                ItemMenuRegister._itemList.dataProvider = ItemMenuConst.getEnabeldAttri(ItemMenuRegister._dicObjdata[ItemMenuRegister._currentActiveObject], ItemMenuRegister._dicObjInfo[ItemMenuRegister._currentActiveObject]);
                loc1 = arg1.stageX;
                loc2 = arg1.stageY;
                loc3 = 5;
                loc1 = loc1 < ItemMenuRegister._layer.stage.stageWidth - ItemMenuRegister._itemList.width - loc3 ? loc1 : loc1 - ItemMenuRegister._itemList.width - loc3;
                loc2 = loc2 < ItemMenuRegister._layer.stage.stageHeight - ItemMenuRegister._itemList.height ? loc2 : loc2 - ItemMenuRegister._itemList.height;
                ItemMenuRegister._itemList.show(loc1, loc2, ItemMenuRegister._layer);
            }
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */static hideHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            ItemMenuRegister.hideOpList();
            return;
        }

        /* internal  */static opItemSelect(arg1: ListEvent): void
        {
            ItemMenuConst.opearte(ItemMenuRegister._itemList.list.dataProvider.getItemAt(arg1.index)["label"], ItemMenuRegister._currentItemData);
            return;
        }

        /* internal */ static /* var */_itemList: ListMenu;

        /* internal */ static /* var */_layer: Object /* flash.display.Sprite */;

        /* internal */ static /* var */_currentActiveObject: Object /* flash.display.InteractiveObject */;

        /* internal */ static /* var */_currentItemData: ItemData=null;

        /* internal */ static /* var */_dicObjInfo: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_dicObjdata: Map<any, any> /* flash.utils.Dictionary */;
    }

            ItemMenuRegister._currentItemData = null;
            ItemMenuRegister._dicObjInfo = new Map<any, any> /* flash.utils.Dictionary */(true);
            ItemMenuRegister._dicObjdata = new Map<any, any> /* flash.utils.Dictionary */(true);
        